package window;


import javax.swing.JFrame;
import javax.swing.JPanel;

import controller.GameListener;

/**
 * @说明 游戏窗口
 * @author 007
 * @二作 crd
 * @三作 Passerby
 * @说明 主窗口
 */
public class MainWindow extends JFrame{
	public static int WINDOWX = 560;	// 与图像的宽一致
	public static int WINDOWY = 800;	// 与图像的高一致
	
	private JPanel jPanel = null;
	private GameListener listener = null;
	private Thread thread = null;

	public MainWindow() {
		init();
	}
	
	public void init() {
		this.setSize(WINDOWX, WINDOWY);
		this.setTitle("飞机大战");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
	}
	
	public void start() {
		if(jPanel !=null) {
			this.add(jPanel);
		}

		if(thread !=null) {
			thread.start();
		}
		
		if (listener != null) {
			this.addMouseListener(listener);
			this.addMouseMotionListener(listener);
		}

		this.setVisible(true);//��ʾ����
		
		if(this.jPanel instanceof Runnable) {
			Runnable run = (Runnable)this.jPanel;
			Thread thread = new Thread(run);
			thread.start();
		}
	}
	
	public void setjPanel(JPanel jPanel) {
		this.jPanel = jPanel;
	}

	public void setListener(GameListener listener) {
		this.listener = listener;
	}
	
	public void setThread(Thread thread) {
		this.thread = thread;
	}
	
}
